﻿<UserControl x:Class="CodeSHARPer.View.CodePadView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  
             xmlns:cmd="clr-namespace:CodeSHARPer"
             xmlns:local="clr-namespace:CodeSHARPer.View"
             xmlns:vm="clr-namespace:CodeSHARPer.ViewModel"
             xmlns:behav="clr-namespace:CodeSHARPer.Behaviour"
             xmlns:avalonDock="http://avalondock.codeplex.com"
             xmlns:CodeCompletion="clr-namespace:ICSharpCode.CodeCompletion;assembly=ICSharpCode.CodeCompletion"
             
             FocusManager.FocusedElement="{Binding ElementName=textEditor}"
             
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="100" d:DesignWidth="300" DataContextChanged="UserControl_DataContextChanged">

    <UserControl.Resources>
        <avalonDock:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
    </UserControl.Resources>

    <Grid x:Name="MainGrid">
        <Grid.RowDefinitions>
            <RowDefinition Height="205*"/>
            <RowDefinition Height="10*"/>
            <RowDefinition Height="85*"/>
        </Grid.RowDefinitions>
        
        <CodeCompletion:CodeTextEditor
            x:Name="textEditor" Grid.Row="0" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
            Document="{Binding Document, UpdateSourceTrigger=PropertyChanged}"
            CodeCompletion="{Binding CodeCompletion}"
            CodeEditorOptions="{Binding TextEditorOptions}"
            FullName="{Binding FilePath}"
            FontFamily="{Binding Font}"
            FontSize="{Binding FontSize}"
            ShowLineNumbers="{Binding ShowLineNumbers}"
            IsReadOnly="{Binding IsReadOnly}"
            IsModified="{Binding IsDirty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">

            <CodeCompletion:CodeTextEditor.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="Save" Command="{Binding SaveCommand}">
                        <MenuItem.Icon>
                            <Image Source="{StaticResource ImageSave}" Height="16"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <Separator/>
                    <MenuItem Command="Cut" Header="Cut">
                        <MenuItem.Icon>
                            <Image Source="{StaticResource ImageCut}" Height="16"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Command="Copy" Header="Copy">
                        <MenuItem.Icon>
                            <Image Source="{StaticResource ImageCopy}" Height="16"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Command="Paste" Header="Paste">
                        <MenuItem.Icon>
                            <Image Source="{StaticResource ImagePaste}" Height="16"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Command="Delete" Header="Delete">
                        <MenuItem.Icon>
                            <Image Source="{StaticResource ImageDelete}" Height="16"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <Separator />
                    <MenuItem Command="cmd:AppCommand.SelectAll" Header="Select All"
                              ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}"/>
                    <Separator />
                    <MenuItem Command="Undo" Header="Undo">
                        <MenuItem.Icon>
                            <Image Source="{StaticResource ImageUndo}" Height="16"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Command="Redo" Header="Redo">
                        <MenuItem.Icon>
                            <Image Source="{StaticResource ImageRedo}" Height="16"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <Separator/>
                    <MenuItem Header="References" Command="cmd:AppCommand.References" ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}">
                        <MenuItem.Icon>
                            <Image Source="{StaticResource ImageReferences}" />
                        </MenuItem.Icon>
                    </MenuItem>
                    <Separator/>
                    <MenuItem Command="{Binding RunCommand}" Header="Run">
                        <MenuItem.Icon>
                            <Image Source="{StaticResource ImageRun}" Height="16"/>
                        </MenuItem.Icon>
                    </MenuItem>
                </ContextMenu>
            </CodeCompletion:CodeTextEditor.ContextMenu>
        </CodeCompletion:CodeTextEditor>

        <TabControl Grid.Row="2" Margin="2" Visibility="{Binding IsOutputVisible, Converter={StaticResource BoolToVisibilityConverter}}" IsVisibleChanged="TabControl_IsVisibleChanged">
            <TabItem Header="Output">
                <FlowDocumentScrollViewer>
                    <FlowDocument>
                        <Paragraph Name="Results" FontFamily="Consolas" FontSize="14" />
                    </FlowDocument>
                </FlowDocumentScrollViewer>
            </TabItem>
        </TabControl>

        <GridSplitter Grid.Row="1" ResizeDirection="Rows" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="5" Width="Auto"/>
    </Grid>
</UserControl>
